package cn.sharp.bbs.service.impl;

import cn.sharp.bbs.dao.DataDictDao;
import cn.sharp.bbs.entity.DO.Datadict;
import cn.sharp.bbs.service.DataDictService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class DataDictServiceImpl implements DataDictService {
    @Resource
    DataDictDao dataDictDao;
    @Override
    public boolean hasCodeWithType(String type, int code) {
        return dataDictDao.selectByTypeAndCode(type, code)!=null;
    }

    @Override
    public boolean hasNameWithType(String type, String name) {
        return dataDictDao.selectByTypeAndName(type, name)!=null;
    }

    @Override
    public int getCode(String type, String name) {
        return dataDictDao.selectByTypeAndName(type, name).getCode();
    }

    @Override
    public String getName(String type, int code) {
        return dataDictDao.selectByTypeAndCode(type, code).getName();
    }

    @Override
    public List<Datadict> listDataDict(String type) {
        return dataDictDao.listByType(type);
    }
}
